import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;

//删除数据库
public class jdbcdemo03 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        try{
            //1.注册驱动
            Driver driver = new Driver();
            //2.获取连接
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/text","root","123456");
            //3.获取数据库操作对象
            stmt = conn.createStatement();
            //4.执行sql语句
            String sql = "delete from text_detail where text_id = 3";
            int count = stmt.executeUpdate(sql);
            System.out.println(count == 1 ? "删除成功":"删除失败");
        }catch (SQLException e){
            e.printStackTrace ();
        }finally {
            //6.释放资源
            if(stmt != null){
                try{
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (conn != null){
                try{
                    conn.close();
                }catch (SQLException e){
                    e.printStackTrace();
                }
            }
        }
    }

    private static class Driver {
    }
}
